package chat;

import java.net.*;


public class PendingPeerLinkedList
{
    private PendingPeerNode zHead = null;
    private PendingPeerNode zTail = null;

    public PendingPeerLinkedList()
    {
    }

    public synchronized PendingPeerNode next()
    {
        while ( zHead == null )
        {
            try
            {
                wait();
            }
            catch ( InterruptedException e )
            {
            }
        }
        PendingPeerNode retval = zHead;
        zHead = zHead.advanceToNext();
        if ( zHead == null )
            zTail = null;
        return retval;
    }

    public synchronized void add( Socket pSocket , PeerInfo pInfo )
    {
        IllegalArgument.ifNull( "Info" , pInfo );
        if ( zHead == null )
            zHead = zTail = new PendingPeerNode( pSocket , pInfo );
        else
            zTail = zTail.newPendingPeer( pSocket , pInfo );
        notifyAll();
    }
}